package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    @GetMapping("teachplan/{courseBaseId}/tree-nodes")
    public TeachplanDTO queryTreeNodesByCourseId(@PathVariable("courseBaseId") Long courseId){
        //1 获得公司id
        Long companyId = SecurityUtil.getCompanyId();
        // 2 调用业务层获得dto数据

        TeachplanDTO dto = teachplanService.queryTreeNodesByCourseId(courseId, companyId);
        return dto;
    }
    @PostMapping("teachplan")
    public TeachplanDTO createOrModifyTeachPlan(@RequestBody TeachplanVO vo) {

        //1. 获得公司Id
        Long companyId = SecurityUtil.getCompanyId();

        //2. 将vo数据转为 dto 数据
        TeachplanDTO dto = TeachplanConvert.INSTANCE.vo2dto(vo);

        //2.调用service获得 dto数据
        TeachplanDTO result = teachplanService.createOrModifyTeachplan(dto, companyId);

        return result;

    }
}
